from django.db import models
from datetime import datetime
from uuid import uuid4
# Create your models here.


"""
建表：1、商品表
1、商品名称
2、商品单价
3、商品说明
4、商品库存
"""



# class Food_sea(models.Model):
#     name = models.CharField(max_length=50)
#     desc = models.CharField(max_length=255)
#     price = models.FloatField(max_length=100)
#     weight = models.CharField(max_length=50)
#     inventory = models.IntegerField()
#     def __str__(self):
#         return self.name


# class Food_fruit(models.Model):
#     name = models.CharField(max_length=50)
#     desc = models.CharField(max_length=255)
#     price = models.FloatField(max_length=100)
#     weight = models.CharField(max_length=50)
#     inventory = models.IntegerField()
#     def __str__(self):
#         return self.name


def upload_image(instance,filename):
    time = datetime.now()
    image_end = filename.split('.')
    res_filename = uuid4().hex
    return "{}/{}/{}.{}".format(time.year,time.month,res_filename,image_end[-1])

class Category(models.Model):
    name = models.CharField(max_length=20,verbose_name="商品分类")
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = "商品分类"
        verbose_name_plural = verbose_name


class Food_vegetables(models.Model):
    name = models.CharField(max_length=50)
    desc = models.CharField(max_length=255)
    price = models.FloatField(max_length=100)
    weight = models.CharField(max_length=50)
    images = models.ImageField(upload_to=upload_image,blank=True)
    inventory = models.IntegerField()
    kind = models.ForeignKey(Category, verbose_name='商品分类', on_delete=None, default=None, null=True)
    def __str__(self):
        return self.name
    class Meta:
        verbose_name = "商品分类"
        verbose_name_plural = verbose_name

# class Food_meat(models.Model):
#     name = models.CharField(max_length=50)
#     desc = models.CharField(max_length=255)
#     price = models.FloatField(max_length=100)
#     weight = models.CharField(max_length=50)
#     inventory = models.IntegerField()
#     def __str__(self):
#         return self.name

#
# class Food_eggs(models.Model):
#     name = models.CharField(max_length=50)
#     desc = models.CharField(max_length=255)
#     price = models.FloatField(max_length=100)
#     weight = models.CharField(max_length=50)
#     inventory = models.IntegerField()
#     def __str__(self):
#         return self.name


# class Food_quick(models.Model):
#     name = models.CharField(max_length=50)
#     desc = models.CharField(max_length=255)
#     price = models.FloatField(max_length=100)
#     weight = models.CharField(max_length=50)
#     inventory = models.IntegerField()
#     def __str__(self):
#         return self.name


